package webdev.adapters;

import java.util.ArrayList;

import webdev.dto.DiaDiemDTO;
import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import dev.danang.R;

public class ListPlaceContentAdapter extends BaseAdapter {

	private static final String TAG = "ListPlaceContentAdapter";
	
	private Context mContext;
	private Resources mResource;
	private ArrayList<DiaDiemDTO> datas;
	
	// LayoutInflater
	private LayoutInflater mInflater;
	
	
	public ListPlaceContentAdapter(Context _context) {
		this.mContext = _context;
		datas = new ArrayList<DiaDiemDTO>();
		mResource = _context.getResources();
		mInflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	public void addContent(DiaDiemDTO place) {
		datas.add(place);
	}
	
	@Override
	public int getCount() {
		return datas.size();
	}
	
	@Override
	public DiaDiemDTO getItem(int position) {
		return datas.get(position);
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		
		if(convertView == null ) {
			convertView = mInflater.inflate(R.layout.item_list_content_place_detail, null);
			viewHolder = new ViewHolder();
			
			viewHolder.mImgContent = (ImageView) convertView.findViewById(R.id.img_content_article_of_place_detail);
			viewHolder.mTxtContent = (TextView) convertView.findViewById(R.id.txt_content_of_place_detail);
			
			convertView.setTag(viewHolder);
			
		}else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		
		viewHolder.mTxtContent.setText(getItem(position).getDescription());
		/*int drawResId = mContext.getResources().getIdentifier(getItem(position).getImageName(), "drawable", mContext.getPackageName());
		viewHolder.mImgContent.setImageResource(drawResId);*/
		
		return convertView;
	}
	
	private class ViewHolder {
		private ImageView mImgContent;
		private TextView mTxtContent;
	}
	
}
